package org.kazao.calendar.demo;

import java.util.Calendar;
import org.kazao.calendar.KazaoCalendar;
import org.kazao.calendar.KazaoCalendarAdapter;
import org.kazao.calendar.KazaoCalendarDialog;
import org.kazao.calendar.KazaoCalendarLocal;

public class Demo extends javax.swing.JPanel {
    
    public Demo() {
        initComponents();
        calendar.addChangeListener(new KazaoCalendarAdapter() {
            public void onChange(Calendar calendar) {
            }
            public void onChange(KazaoCalendar calendar) {
                lShortDate.setText(calendar.getShortDate());
                lLongDate.setText(calendar.getLongDate());
            }
            public void onDoubleClick() {
            }
        });
        
        tDateTimePickerFormat.setText(dateTimePicker.getFormat());
    }
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        pCalendar = new javax.swing.JPanel();
        calendar = new org.kazao.calendar.KazaoCalendar();
        cbPrevious = new javax.swing.JCheckBox();
        cbNext = new javax.swing.JCheckBox();
        cbInfo = new javax.swing.JCheckBox();
        cbxLocal = new javax.swing.JComboBox();
        pShortDate = new javax.swing.JPanel();
        lShortDate = new javax.swing.JLabel();
        pLongDate = new javax.swing.JPanel();
        lLongDate = new javax.swing.JLabel();
        pDateTimePicker = new javax.swing.JPanel();
        dateTimePicker = new org.kazao.calendar.KazaoCalendarDateTime();
        cbDateTimePickerEditable = new javax.swing.JCheckBox();
        cbDateTimePickerEnable = new javax.swing.JCheckBox();
        cbDateTimePickerShowButton = new javax.swing.JCheckBox();
        tDateTimePickerFormat = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cDateTimePickerFormat = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        pDatePicker = new javax.swing.JPanel();
        kazaoCalendarDate1 = new org.kazao.calendar.KazaoCalendarDate();
        kazaoCalendarDateTime1 = new org.kazao.calendar.KazaoCalendarDateTime();
        kazaoCalendarDateTime2 = new org.kazao.calendar.KazaoCalendarDateTime();
        kazaoCalendarDateTime3 = new org.kazao.calendar.KazaoCalendarDateTime();
        kazaoCalendarDateTime4 = new org.kazao.calendar.KazaoCalendarDateTime();
        pTimePicker = new javax.swing.JPanel();
        kazaoCalendarTime2 = new org.kazao.calendar.KazaoCalendarTime();
        kazaoCalendarDateTime5 = new org.kazao.calendar.KazaoCalendarDateTime();
        pDialaog = new javax.swing.JPanel();
        lDate = new javax.swing.JLabel();
        cDialog = new javax.swing.JButton();

        setLayout(null);

        pCalendar.setLayout(null);

        pCalendar.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Single Calendar"));
        pCalendar.add(calendar);
        calendar.setBounds(10, 20, 270, 156);

        cbPrevious.setSelected(true);
        cbPrevious.setText("Previous Button");
        cbPrevious.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbPrevious.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbPrevious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPreviousActionPerformed(evt);
            }
        });

        pCalendar.add(cbPrevious);
        cbPrevious.setBounds(146, 178, 132, 15);

        cbNext.setSelected(true);
        cbNext.setText("Next Button");
        cbNext.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbNext.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbNextActionPerformed(evt);
            }
        });

        pCalendar.add(cbNext);
        cbNext.setBounds(10, 180, 132, 15);

        cbInfo.setSelected(true);
        cbInfo.setText("Show Info");
        cbInfo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbInfo.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbInfoActionPerformed(evt);
            }
        });

        pCalendar.add(cbInfo);
        cbInfo.setBounds(10, 200, 270, 15);

        cbxLocal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KazaoCalendarLocal", "KazaoCalendarLocalUS", "KazaoCalendarLocalEN", "KazaoCalendarLocalID" }));
        cbxLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxLocalActionPerformed(evt);
            }
        });

        pCalendar.add(cbxLocal);
        cbxLocal.setBounds(10, 276, 268, 22);

        pShortDate.setLayout(null);

        pShortDate.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Short Date"));
        lShortDate.setText(" ");
        pShortDate.add(lShortDate);
        lShortDate.setBounds(8, 24, 182, 14);

        pCalendar.add(pShortDate);
        pShortDate.setBounds(10, 218, 198, 0);

        pLongDate.setLayout(null);

        pLongDate.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Short Date"));
        lLongDate.setText(" ");
        pLongDate.add(lLongDate);
        lLongDate.setBounds(10, 24, 250, 14);

        pCalendar.add(pLongDate);
        pLongDate.setBounds(10, 220, 270, 51);

        add(pCalendar);
        pCalendar.setBounds(6, 10, 290, 308);

        pDateTimePicker.setLayout(null);

        pDateTimePicker.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Date & Time Picker"));
        pDateTimePicker.setPreferredSize(new java.awt.Dimension(0, 0));
        pDateTimePicker.add(dateTimePicker);
        dateTimePicker.setBounds(10, 28, 206, 20);

        cbDateTimePickerEditable.setSelected(true);
        cbDateTimePickerEditable.setText("Editable");
        cbDateTimePickerEditable.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbDateTimePickerEditable.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbDateTimePickerEditable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDateTimePickerEditableActionPerformed(evt);
            }
        });

        pDateTimePicker.add(cbDateTimePickerEditable);
        cbDateTimePickerEditable.setBounds(10, 56, 116, 15);

        cbDateTimePickerEnable.setSelected(true);
        cbDateTimePickerEnable.setText("Enable");
        cbDateTimePickerEnable.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbDateTimePickerEnable.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbDateTimePickerEnable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDateTimePickerEnableActionPerformed(evt);
            }
        });

        pDateTimePicker.add(cbDateTimePickerEnable);
        cbDateTimePickerEnable.setBounds(131, 56, 84, 15);

        cbDateTimePickerShowButton.setSelected(true);
        cbDateTimePickerShowButton.setText("Show Button");
        cbDateTimePickerShowButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbDateTimePickerShowButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cbDateTimePickerShowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDateTimePickerShowButtonActionPerformed(evt);
            }
        });

        pDateTimePicker.add(cbDateTimePickerShowButton);
        cbDateTimePickerShowButton.setBounds(10, 76, 206, 15);

        pDateTimePicker.add(tDateTimePickerFormat);
        tDateTimePickerFormat.setBounds(10, 118, 140, 20);

        jLabel3.setText("Custom Format");
        pDateTimePicker.add(jLabel3);
        jLabel3.setBounds(10, 98, 190, 14);

        cDateTimePickerFormat.setText("Set");
        cDateTimePickerFormat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cDateTimePickerFormatActionPerformed(evt);
            }
        });

        pDateTimePicker.add(cDateTimePickerFormat);
        cDateTimePickerFormat.setBounds(156, 116, 60, 23);

        jLabel1.setText("Note:");
        pDateTimePicker.add(jLabel1);
        jLabel1.setBounds(10, 142, 204, 14);

        jLabel2.setText("<html>d = date, m = month, y = year<br>h = hour, i = minnute, s = second</html>");
        pDateTimePicker.add(jLabel2);
        jLabel2.setBounds(10, 156, 204, 34);

        add(pDateTimePicker);
        pDateTimePicker.setBounds(298, 10, 228, 198);

        pDatePicker.setLayout(null);

        pDatePicker.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Date Picker"));
        pDatePicker.add(kazaoCalendarDate1);
        kazaoCalendarDate1.setBounds(10, 22, 96, 24);

        kazaoCalendarDateTime1.setButtonVisible(false);
        kazaoCalendarDateTime1.setFormat("ddmmmmyyyy");
        pDatePicker.add(kazaoCalendarDateTime1);
        kazaoCalendarDateTime1.setBounds(72, 76, 140, 22);

        kazaoCalendarDateTime2.setFormat("dd-mm-yyyy");
        pDatePicker.add(kazaoCalendarDateTime2);
        kazaoCalendarDateTime2.setBounds(110, 22, 108, 24);

        kazaoCalendarDateTime3.setButtonVisible(false);
        kazaoCalendarDateTime3.setFormat("dddmmmmyyyyy");
        pDatePicker.add(kazaoCalendarDateTime3);
        kazaoCalendarDateTime3.setBounds(10, 50, 188, 22);

        kazaoCalendarDateTime4.setButtonVisible(false);
        kazaoCalendarDateTime4.setFormat("ddmmmyy");
        pDatePicker.add(kazaoCalendarDateTime4);
        kazaoCalendarDateTime4.setBounds(10, 76, 58, 22);

        add(pDatePicker);
        pDatePicker.setBounds(298, 210, 228, 108);

        pTimePicker.setLayout(null);

        pTimePicker.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Time Picker"));
        pTimePicker.add(kazaoCalendarTime2);
        kazaoCalendarTime2.setBounds(10, 22, 78, 22);

        kazaoCalendarDateTime5.setButtonVisible(false);
        kazaoCalendarDateTime5.setFormat("dddiiisss");
        pTimePicker.add(kazaoCalendarDateTime5);
        kazaoCalendarDateTime5.setBounds(92, 22, 124, 22);

        add(pTimePicker);
        pTimePicker.setBounds(300, 320, 226, 58);

        pDialaog.setLayout(null);

        pDialaog.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dialog Calendar"));
        lDate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lDate.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pDialaog.add(lDate);
        lDate.setBounds(10, 25, 152, 22);

        cDialog.setText("Show Dialog");
        cDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cDialogActionPerformed(evt);
            }
        });

        pDialaog.add(cDialog);
        cDialog.setBounds(166, 26, 114, 23);

        add(pDialaog);
        pDialaog.setBounds(6, 320, 290, 58);

    }// </editor-fold>//GEN-END:initComponents
    
    private void cDateTimePickerFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cDateTimePickerFormatActionPerformed
        dateTimePicker.setFormat(tDateTimePickerFormat.getText());
    }//GEN-LAST:event_cDateTimePickerFormatActionPerformed
    
    private void cbDateTimePickerShowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDateTimePickerShowButtonActionPerformed
        dateTimePicker.setButtonVisible(cbDateTimePickerShowButton.isSelected());
    }//GEN-LAST:event_cbDateTimePickerShowButtonActionPerformed
    
    private void cDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cDialogActionPerformed
        KazaoCalendarDialog dialog = new KazaoCalendarDialog();
        if (dialog.showCalendar() == dialog.COMMAND_APPROVE) {
            Calendar cal = dialog.getCalendar();
            lDate.setText(cal.get(cal.DATE)+"/"+(cal.get(cal.MONTH)+1)+"/"+cal.get(cal.YEAR));
        }
    }//GEN-LAST:event_cDialogActionPerformed
    
    private void cbxLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxLocalActionPerformed
        try {
            calendar.setLocalize((KazaoCalendarLocal) getClass().forName("org.kazao.calendar."+cbxLocal.getSelectedItem().toString()).newInstance());
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_cbxLocalActionPerformed
    
    private void cbInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbInfoActionPerformed
        calendar.setInfoVisible(cbInfo.isSelected());
    }//GEN-LAST:event_cbInfoActionPerformed
    
    private void cbNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbNextActionPerformed
        calendar.setNextButtonVisible(cbNext.isSelected());
    }//GEN-LAST:event_cbNextActionPerformed
    
    private void cbPreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPreviousActionPerformed
        calendar.setPrevButtonVisible(cbPrevious.isSelected());
    }//GEN-LAST:event_cbPreviousActionPerformed
    
    private void cbDateTimePickerEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDateTimePickerEnableActionPerformed
        dateTimePicker.setEnabled(cbDateTimePickerEnable.isSelected());
    }//GEN-LAST:event_cbDateTimePickerEnableActionPerformed
    
    private void cbDateTimePickerEditableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDateTimePickerEditableActionPerformed
        dateTimePicker.setEditable(cbDateTimePickerEditable.isSelected());
    }//GEN-LAST:event_cbDateTimePickerEditableActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton cDateTimePickerFormat;
    public javax.swing.JButton cDialog;
    public org.kazao.calendar.KazaoCalendar calendar;
    public javax.swing.JCheckBox cbDateTimePickerEditable;
    public javax.swing.JCheckBox cbDateTimePickerEnable;
    public javax.swing.JCheckBox cbDateTimePickerShowButton;
    public javax.swing.JCheckBox cbInfo;
    public javax.swing.JCheckBox cbNext;
    public javax.swing.JCheckBox cbPrevious;
    public javax.swing.JComboBox cbxLocal;
    public org.kazao.calendar.KazaoCalendarDateTime dateTimePicker;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel3;
    public org.kazao.calendar.KazaoCalendarDate kazaoCalendarDate1;
    public org.kazao.calendar.KazaoCalendarDateTime kazaoCalendarDateTime1;
    public org.kazao.calendar.KazaoCalendarDateTime kazaoCalendarDateTime2;
    public org.kazao.calendar.KazaoCalendarDateTime kazaoCalendarDateTime3;
    public org.kazao.calendar.KazaoCalendarDateTime kazaoCalendarDateTime4;
    public org.kazao.calendar.KazaoCalendarDateTime kazaoCalendarDateTime5;
    public org.kazao.calendar.KazaoCalendarTime kazaoCalendarTime2;
    public javax.swing.JLabel lDate;
    public javax.swing.JLabel lLongDate;
    public javax.swing.JLabel lShortDate;
    public javax.swing.JPanel pCalendar;
    public javax.swing.JPanel pDatePicker;
    public javax.swing.JPanel pDateTimePicker;
    public javax.swing.JPanel pDialaog;
    public javax.swing.JPanel pLongDate;
    public javax.swing.JPanel pShortDate;
    public javax.swing.JPanel pTimePicker;
    public javax.swing.JTextField tDateTimePickerFormat;
    // End of variables declaration//GEN-END:variables
    
}
